package com.demo.utils;

import java.io.OutputStream;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class R {
	public static void closeQuietly(AutoCloseable obj) {
		if (obj == null) {
			return;
		} 
		
		try {
			obj.close();
			obj = null;
		} catch(Exception e) {		
		}
	}
	
	public static void closeQuietly(OutputStream obj) {
		if (obj == null) {
			return;
		}
		
		try {
			obj.flush();
			obj.close();
			obj = null;
		} catch (Exception e) {			
		}
	}
	
	public static <T> void dispose(List<T> list) {
		if (list != null) {
			list.clear();
		}
		
		list = null;
	}
	
	public static <K, V> void dispose(Map<K, V> map) {
		if (map != null) {
			map.clear();
		}
		
		map = null;
	}
	
	public static <T> void dispose(Set<T> set) {
		if (set != null) {
			set.clear();
		}
		
		set = null;
	}
	
	public static <T> void dispose(Collection<T> collection) {
		if (collection != null) {
			collection.clear();
		}
		
		collection = null;
	}
	
	public static <T> void dispose(T obj) {
		if (obj != null) {
			obj = null;
		}
	}
}
